package com.fjxd.plane.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fjxd.plane.pojo.Airlines;
import com.fjxd.plane.pojo.Plane;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author wz
 */
@Mapper
public interface PlaneMapper extends BaseMapper<Plane> {
    /**
     * @return 返回所有飞机数据
     */
    @Select("select * from plane")
    @ResultMap("resultMap1")
    public List<Plane> getPlaneAll();

    /**
     * @return 返回单个飞机
     * @param id 输入飞机id
     */
    @Select("select * from plane where id=#{id}")
    @Results(id="resultMap1",value = {
            @Result(column="a_id",property="aId"),
            @Result(column="a_id",property="airlines",javaType = Airlines.class,
                    one=@One(select="com.fjxd.plane.mapper.AirlinesMapper.getAirlinesById"))
    })
    public Plane getPlaneById(Integer id);

    /**
     * @return 新增飞机
     * @param plane 飞机对象
     */
    @Insert("insert into plane (a_id, serial, name, take_number, first_class, business_class, economy_class ,speed) values " +
            "(#{aId}, #{serial}, #{name}, #{takeNumber},#{firstClass},#{businessClass},#{economyClass},#{speed})")
    int addPlane(Plane plane);

    @Select("select p.id,a_id from plane as p join airlines as a on a.id=p.a_id where a.id=#{id}")
    List<Plane> getAirlinesByName(Integer id);
}
